package com.ourteam.workspace.dao.impl;

import com.ourteam.workspace.dao.IWorkspaceResourceUIPageRelateDAO;
import com.ourteam.workspace.dao.WorkspaceResourceUIPageRelate;
import com.ourteam.workspace.dao.WorkspaceResourceUIPageRelateDAOQueryBean;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.jdbc.core.RowMapper;

/**
 * Template Name : DAO服务对象 Template Version : 1 Template Last Modfiy Date : Fri Nov 17 11:00:11 CST
 * 2017 Auto Generate Date : 2018-11-30 18:42:35 Warning ! This file will be overwrite when
 * regenerate !
 */
public class AbstractWorkspaceResourceUIPageRelateDAOJdbcImpl extends AbstractSpringDAO
    implements IWorkspaceResourceUIPageRelateDAO {

  public static final String[] ENTITY_FIELDS =
      new String[] {
        Id,
        WorkspaceResourceId,
        UiPageId,
        LastGenCodeTime,
        SubmitterId,
        SubmitterName,
        Status,
        Remarks,
        ResourcePath,
        ResourceType,
        WorkspaceId,
        PageCode,
        PageName,
        UiDomainId,
        UiDomainName,
        UiDomainCode
      };

  public static final String[] ENTITY_PROPERTIES =
      new String[] {
        _DataObjectProperty.Id,
        _DataObjectProperty.WorkspaceResourceId,
        _DataObjectProperty.UiPageId,
        _DataObjectProperty.LastGenCodeTime,
        _DataObjectProperty.SubmitterId,
        _DataObjectProperty.SubmitterName,
        _DataObjectProperty.Status,
        _DataObjectProperty.Remarks,
        _DataObjectProperty.ResourcePath,
        _DataObjectProperty.ResourceType,
        _DataObjectProperty.WorkspaceId,
        _DataObjectProperty.PageCode,
        _DataObjectProperty.PageName,
        _DataObjectProperty.UiDomainId,
        _DataObjectProperty.UiDomainName,
        _DataObjectProperty.UiDomainCode
      };

  public static final String[] ENTITY_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {};

  private static String relatedJoinSQL = null;

  private static String basicFilterSQL = null;

  private DataAccessObjectHelper<
          WorkspaceResourceUIPageRelate, WorkspaceResourceUIPageRelateDAOQueryBean>
      daoHelper;

  public AbstractWorkspaceResourceUIPageRelateDAOJdbcImpl() {
    super();
    daoHelper =
        new DataAccessObjectHelper<
            WorkspaceResourceUIPageRelate, WorkspaceResourceUIPageRelateDAOQueryBean>(this);
  }

  protected String getEntityName() {
    return EntityName;
  }

  protected String[] getEntityFields() {
    return ENTITY_FIELDS;
  }

  protected String[] getEntityProperties() {
    return ENTITY_PROPERTIES;
  }

  protected String[] getEntityPKFields() {
    return ENTITY_PK_FIELDS;
  }

  protected String[] getEntityAutoGenPKFields() {
    return ENTITY_AUTO_GEN_PK_FIELDS;
  }

  protected String[] getEntityUniqueFields() {
    return ENTITY_UNIQUE_FIELDS;
  }

  protected String getBaiscQueryFilter() {

    if (basicFilterSQL == null) {
      StringBuffer basicFilterSQLbuffer = new StringBuffer();

      basicFilterSQL = basicFilterSQLbuffer.toString();
    }

    return basicFilterSQL;
  }

  protected String getRelatedJoinSQL() {

    if (relatedJoinSQL == null) {
      StringBuffer relatedJoinSQLBuffer = new StringBuffer();

      relatedJoinSQLBuffer
          .append(" LEFT JOIN ")
          .append(com.ourteam.workspace.dao.IWorkspaceResourceDAO.EntityName)
          .append(" RELATED_Y9KSA7_WorkspaceResource ");

      relatedJoinSQLBuffer.append(" ON ( ");

      relatedJoinSQLBuffer.append(
          StringUtils.replace(
              com.ourteam.workspace.dao.IWorkspaceResourceDAO.Id,
              com.ourteam.workspace.dao.IWorkspaceResourceDAO.EntityName + ".",
              "RELATED_Y9KSA7_WorkspaceResource."));
      relatedJoinSQLBuffer.append(" = ").append(WorkspaceResourceId);

      relatedJoinSQLBuffer.append(" ) ");

      relatedJoinSQLBuffer
          .append(" LEFT JOIN ")
          .append(com.ourteam.product.ui.dao.IProductUIPageDAO.EntityName)
          .append(" RELATED_O4Z9I5_ProductUIPage ");

      relatedJoinSQLBuffer.append(" ON ( ");

      relatedJoinSQLBuffer.append(
          StringUtils.replace(
              com.ourteam.product.ui.dao.IProductUIPageDAO.Id,
              com.ourteam.product.ui.dao.IProductUIPageDAO.EntityName + ".",
              "RELATED_O4Z9I5_ProductUIPage."));
      relatedJoinSQLBuffer.append(" = ").append(UiPageId);

      relatedJoinSQLBuffer.append(" ) ");

      relatedJoinSQLBuffer
          .append(" LEFT JOIN ")
          .append(com.ourteam.product.ui.dao.IProductUIDomainDAO.EntityName)
          .append(" RELATED_FZ84CH_ProductUIDomain ");

      relatedJoinSQLBuffer.append(" ON ( ");

      relatedJoinSQLBuffer.append(
          StringUtils.replace(
              com.ourteam.product.ui.dao.IProductUIDomainDAO.Id,
              com.ourteam.product.ui.dao.IProductUIDomainDAO.EntityName + ".",
              "RELATED_FZ84CH_ProductUIDomain."));
      relatedJoinSQLBuffer.append(" = ").append(UiDomainId);

      relatedJoinSQLBuffer.append(" ) ");

      relatedJoinSQL = relatedJoinSQLBuffer.toString();
    }

    return relatedJoinSQL;
  }

  /**
   * Check Data Unique
   *
   * @param aWorkspaceResourceUIPageRelate
   * @throws Exception
   */
  public boolean checkIsUnique(WorkspaceResourceUIPageRelate aWorkspaceResourceUIPageRelate)
      throws Exception {

    if (aWorkspaceResourceUIPageRelate == null) {
      return true;
    }

    List valueList = new ArrayList();

    List pkValueList = new ArrayList();

    pkValueList.add(aWorkspaceResourceUIPageRelate.getId());

    return isUnique(
        valueList.toArray(new Object[valueList.size()]),
        pkValueList.toArray(new Object[pkValueList.size()]));
  }

  /**
   * Insert Data
   *
   * @param aWorkspaceResourceUIPageRelate
   * @throws Exception
   */
  public void insert(WorkspaceResourceUIPageRelate aWorkspaceResourceUIPageRelate)
      throws Exception {

    super.doInsert(aWorkspaceResourceUIPageRelate);
  }

  /**
   * Batch Insert Datas
   *
   * @param aWorkspaceResourceUIPageRelate
   * @throws Exception
   */
  public void batchInsert(WorkspaceResourceUIPageRelate[] aWorkspaceResourceUIPageRelates)
      throws Exception {

    super.doBatchInsert(aWorkspaceResourceUIPageRelates);
  }

  /**
   * Delete Data
   *
   * @param final long id *
   * @throws Exception
   */
  public void delete(final long id) throws Exception {

    super.doDeleteById(new Object[] {new Long(id)});
  }

  /**
   * Delete Datas
   *
   * @param queryBean
   * @throws Exception
   */
  public void delete(WorkspaceResourceUIPageRelateDAOQueryBean queryBean) throws Exception {

    super.doDeleteByQuery(queryBean);
  }

  public void delete(WorkspaceResourceUIPageRelate aWorkspaceResourceUIPageRelate)
      throws Exception {

    delete(aWorkspaceResourceUIPageRelate.getId());
  }

  /**
   * Update Data Selective
   *
   * @param aWorkspaceResourceUIPageRelate
   * @throws Exception
   */
  public void update(WorkspaceResourceUIPageRelate aWorkspaceResourceUIPageRelate)
      throws Exception {

    if (aWorkspaceResourceUIPageRelate.getId() == 0) {
      throw new Exception("Can not update object data whith out primary key value");
    }

    super.doUpdate(aWorkspaceResourceUIPageRelate);

    WorkspaceResourceUIPageRelate tempObj = findById(aWorkspaceResourceUIPageRelate.getId());

    if (tempObj != null) {
      PropertyUtils.copyProperties(aWorkspaceResourceUIPageRelate, tempObj);
    }
  }

  /**
   * Batch Update Datas
   *
   * @param aWorkspaceResourceUIPageRelates[]
   * @throws Exception
   */
  public void batchUpdate(WorkspaceResourceUIPageRelate[] aWorkspaceResourceUIPageRelates)
      throws Exception {

    super.doBatchUpdate(aWorkspaceResourceUIPageRelates);
  }

  /**
   * Update Data By Condictions
   *
   * @param aWorkspaceResourceUIPageRelate
   * @param aValueCriteria
   * @param aTransaction
   * @throws Exception
   */
  public void update(
      WorkspaceResourceUIPageRelate aWorkspaceResourceUIPageRelate,
      WorkspaceResourceUIPageRelateDAOQueryBean aQueryBean)
      throws Exception {

    super.doUpdateByQuery(aWorkspaceResourceUIPageRelate, aQueryBean);
  }

  /**
   * Update Data By Condictions
   *
   * @param aQueryBean
   * @throws Exception
   */
  public void update(WorkspaceResourceUIPageRelateDAOQueryBean aQueryBean) throws Exception {
    super.doUpdateByQuery(aQueryBean);
  }

  protected void checkNullValue(WorkspaceResourceUIPageRelate aWorkspaceResourceUIPageRelate)
      throws Exception {}

  /**
   * Get Data By ID
   *
   * @param final long id * @return ${businessObject.name}
   * @throws Exception
   */
  public WorkspaceResourceUIPageRelate findById(final long id) throws Exception {

    WorkspaceResourceUIPageRelateDAOQueryBean queryBean =
        new WorkspaceResourceUIPageRelateDAOQueryBean();

    WorkspaceResourceUIPageRelateDAOQueryBean.Criteria criteria = queryBean.createCriteria();

    criteria.andIdEqualTo(id);

    // queryBean.setDistinct(true);

    WorkspaceResourceUIPageRelate[] WorkspaceResourceUIPageRelates = query(queryBean);

    if (WorkspaceResourceUIPageRelates.length == 0) {
      return null;
    } else {
      return WorkspaceResourceUIPageRelates[0];
    }
  }

  /**
   * Query Data
   *
   * @param queryBean
   * @return WorkspaceResourceUIPageRelate[]
   * @throws Exception
   */
  public WorkspaceResourceUIPageRelate[] query(WorkspaceResourceUIPageRelateDAOQueryBean queryBean)
      throws Exception {

    List result = super.doQuery(queryBean, new JdbcWorkspaceResourceUIPageRelateRowMapper());

    return (WorkspaceResourceUIPageRelate[])
        result.toArray(new WorkspaceResourceUIPageRelate[result.size()]);
  }

  /**
   * Query ${businessObject.name} Selective
   *
   * @param queryBean
   * @return Map[]
   * @model
   * @throws Exception
   */
  public Map<String, Object>[] querySelective(WorkspaceResourceUIPageRelateDAOQueryBean queryBean)
      throws Exception {

    if (queryBean.getSelectProperties().isEmpty()) {
      queryBean.addAllSelectProperties();
    }

    return super.doQuerySelective(queryBean);
  }

  /**
   * Query Data Count
   *
   * @param queryBean
   * @return int
   * @throws Exception
   */
  public int queryCount(WorkspaceResourceUIPageRelateDAOQueryBean queryBean) throws Exception {

    return super.doQueryCount(queryBean);
  }

  public void synchronize(
      WorkspaceResourceUIPageRelate[] aWorkspaceResourceUIPageRelates,
      WorkspaceResourceUIPageRelateDAOQueryBean queryBean)
      throws Exception {
    daoHelper.synchronize(aWorkspaceResourceUIPageRelates, queryBean);
  }

  public void synchronize(
      WorkspaceResourceUIPageRelate[] aWorkspaceResourceUIPageRelates,
      WorkspaceResourceUIPageRelateDAOQueryBean queryBean,
      net.dao.IDataAccessInterface.ISynchronizeCallback<WorkspaceResourceUIPageRelate> callBack)
      throws Exception {
    daoHelper.synchronize(aWorkspaceResourceUIPageRelates, queryBean, callBack);
  }

  public static class JdbcWorkspaceResourceUIPageRelateRowMapper
      implements RowMapper<WorkspaceResourceUIPageRelate> {

    public WorkspaceResourceUIPageRelate mapRow(ResultSet resultSet, int arg1) throws SQLException {
      WorkspaceResourceUIPageRelate object = new WorkspaceResourceUIPageRelate();

      int columnIndex = 1;

      int __dataType;

      try {

        Object id = null;

        id = resultSet.getObject(columnIndex++);

        object.setIdNull(resultSet.getBoolean(columnIndex++));

        if (id != null) {

          setBeanValue(object, _DataObjectProperty.Id, id);
        }

        Object workspaceResourceId = null;

        workspaceResourceId = resultSet.getObject(columnIndex++);

        object.setWorkspaceResourceIdNull(resultSet.getBoolean(columnIndex++));

        if (workspaceResourceId != null) {

          setBeanValue(object, _DataObjectProperty.WorkspaceResourceId, workspaceResourceId);
        }

        Object uiPageId = null;

        uiPageId = resultSet.getObject(columnIndex++);

        object.setUiPageIdNull(resultSet.getBoolean(columnIndex++));

        if (uiPageId != null) {

          setBeanValue(object, _DataObjectProperty.UiPageId, uiPageId);
        }

        Object lastGenCodeTime = null;

        __dataType = resultSet.getMetaData().getColumnType(columnIndex);

        if (__dataType == java.sql.Types.DATE
            || __dataType == java.sql.Types.TIME
            || __dataType == java.sql.Types.TIMESTAMP) {
          lastGenCodeTime = resultSet.getTimestamp(columnIndex++);

        } else {
          lastGenCodeTime = resultSet.getObject(columnIndex++);
        }

        object.setLastGenCodeTimeNull(resultSet.getBoolean(columnIndex++));

        if (lastGenCodeTime != null) {

          setBeanValue(object, _DataObjectProperty.LastGenCodeTime, lastGenCodeTime);
        }

        Object submitterId = null;

        submitterId = resultSet.getObject(columnIndex++);

        object.setSubmitterIdNull(resultSet.getBoolean(columnIndex++));

        if (submitterId != null) {

          setBeanValue(object, _DataObjectProperty.SubmitterId, submitterId);
        }

        Object submitterName = null;

        submitterName = resultSet.getObject(columnIndex++);

        object.setSubmitterNameNull(resultSet.getBoolean(columnIndex++));

        if (submitterName != null) {

          setBeanValue(object, _DataObjectProperty.SubmitterName, submitterName);
        }

        Object status = null;

        status = resultSet.getObject(columnIndex++);

        object.setStatusNull(resultSet.getBoolean(columnIndex++));

        if (status != null) {

          setBeanValue(object, _DataObjectProperty.Status, status);
        }

        Object remarks = null;

        remarks = resultSet.getObject(columnIndex++);

        object.setRemarksNull(resultSet.getBoolean(columnIndex++));

        if (remarks != null) {

          setBeanValue(object, _DataObjectProperty.Remarks, remarks);
        }

        Object resourcePath = null;

        resourcePath = resultSet.getObject(columnIndex++);

        object.setResourcePathNull(resultSet.getBoolean(columnIndex++));

        if (resourcePath != null) {

          setBeanValue(object, _DataObjectProperty.ResourcePath, resourcePath);
        }

        Object resourceType = null;

        resourceType = resultSet.getObject(columnIndex++);

        object.setResourceTypeNull(resultSet.getBoolean(columnIndex++));

        if (resourceType != null) {

          setBeanValue(object, _DataObjectProperty.ResourceType, resourceType);
        }

        Object workspaceId = null;

        workspaceId = resultSet.getObject(columnIndex++);

        object.setWorkspaceIdNull(resultSet.getBoolean(columnIndex++));

        if (workspaceId != null) {

          setBeanValue(object, _DataObjectProperty.WorkspaceId, workspaceId);
        }

        Object pageCode = null;

        pageCode = resultSet.getObject(columnIndex++);

        object.setPageCodeNull(resultSet.getBoolean(columnIndex++));

        if (pageCode != null) {

          setBeanValue(object, _DataObjectProperty.PageCode, pageCode);
        }

        Object pageName = null;

        pageName = resultSet.getObject(columnIndex++);

        object.setPageNameNull(resultSet.getBoolean(columnIndex++));

        if (pageName != null) {

          setBeanValue(object, _DataObjectProperty.PageName, pageName);
        }

        Object uiDomainId = null;

        uiDomainId = resultSet.getObject(columnIndex++);

        object.setUiDomainIdNull(resultSet.getBoolean(columnIndex++));

        if (uiDomainId != null) {

          setBeanValue(object, _DataObjectProperty.UiDomainId, uiDomainId);
        }

        Object uiDomainName = null;

        uiDomainName = resultSet.getObject(columnIndex++);

        object.setUiDomainNameNull(resultSet.getBoolean(columnIndex++));

        if (uiDomainName != null) {

          setBeanValue(object, _DataObjectProperty.UiDomainName, uiDomainName);
        }

        Object uiDomainCode = null;

        uiDomainCode = resultSet.getObject(columnIndex++);

        object.setUiDomainCodeNull(resultSet.getBoolean(columnIndex++));

        if (uiDomainCode != null) {

          setBeanValue(object, _DataObjectProperty.UiDomainCode, uiDomainCode);
        }

        return object;
      } catch (Exception e) {
        throw new SQLException(e.getMessage());
      }
    }
  }
}
